#include "Hardware.h"

#define ADC_VALUE_LIMIT 4
#define ADC_VALUE_MAX 3000
#define ADC_VALUE_MID 2000
#define ADC_VALUE_MIN 1000
#define Det(a, b) (a > b) ? (a - b) : (b - a)

uint8_t Key_Scan(uint16_t ADC_Value)
{
    uint8_t KeyNum = 0;
    static uint16_t ADC_Last = 0, ADC_Now = 0;
    ADC_Now = ADC_Value;
    if(Det(ADC_Last, ADC_Now) < ADC_VALUE_LIMIT)
    {
        if(ADC_Now > ADC_VALUE_MAX)
        {
            KeyNum = 3;
        }else if(ADC_Now > ADC_VALUE_MID)
        {
            KeyNum = 2;
        }else if(ADC_Now > ADC_VALUE_MIN)
        {
            KeyNum = 1;
        }
    }
    ADC_Last = ADC_Now;
    return KeyNum;
}


